/**
 * 0232
 *  
 * @Author : roryrywang
 * @DateTime : 2024/8/14 20:52
 */

#include <iostream>
#include <vector>
#include <stack>

using namespace std;

class MyQueue {
private:
    stack<int> s1;
    stack<int> s2;
    int flag = 1;
public:
    MyQueue() {

    }

    void push(int x) {
        if (flag == -1) {
            for (int i = s2.size() - 1; i >= 0; --i) {
                s1.push(s2.top());
                s2.pop();
            }
            flag = 1;
        }
        s1.push(x);
    }

    int pop() {
        if (flag == 1) {
            for (int i = s1.size() - 1; i >= 0; --i) {
                s2.push(s1.top());
                s1.pop();
            }
            flag = -1;
        }
        int res = s2.top();
        s2.pop();
        return res;
    }

    int peek() {
        if (flag == 1) {
            for (int i = s1.size() - 1; i >= 0; --i) {
                s2.push(s1.top());
                s1.pop();
            }
            flag = -1;
        }
        return s2.top();
    }

    bool empty() {
        return s1.empty() && s2.empty();
    }
};

int main() {

    return 0;
}